package timing.ukulele.third.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Description 概要描述
 * @Author zh
 * @Date 2025-10-28 17:47
 */
public class StringExtractor {

    /**
     * 提取多种符号内的内容
     */
    public static List<String> extractContent(String input, String startSymbol, String endSymbol) {
        List<String> result = new ArrayList<>();

        // 转义特殊字符
        String escapedStart = Pattern.quote(startSymbol);
        String escapedEnd = Pattern.quote(endSymbol);

        String regex = escapedStart + "(.*?)" + escapedEnd;
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(input);

        while (matcher.find()) {
            result.add(matcher.group(1));
        }

        return result;
    }

    /**
     * 提取引号内的内容（单引号或双引号）
     */
    public static List<String> extractQuotedContent(String input) {
        List<String> result = new ArrayList<>();

        // 匹配单引号或双引号内的内容
        Pattern pattern = Pattern.compile("['\"](.*?)['\"]");
        Matcher matcher = pattern.matcher(input);

        while (matcher.find()) {
            result.add(matcher.group(1));
        }

        return result;
    }

}
